<?php
/**
 * Created by PhpStorm.
 * User: 94004
 * Date: 2017/12/30
 * Time: 19:41
 */
header("Content-Type:text/html;charset=utf-8;");
require_once "../util/db_helper.php";
//$articleTotalSql = " SELECT COUNT(*) AS articleTotal FROM articles a ";
//$articleTotalRes = query($articleTotalSql);
//$articleDarftedSql = " SELECT COUNT(*) AS articleDarfted FROM articles a WHERE status=0";
//$articleDarftedRes = query($articleDarftedSql);
//$categoryTotalSql = " SELECT COUNT(*) AS categoryTotal FROM categories c ";
//$categoryTotalRes = query($categoryTotalSql);
//$commentTotalSql = " SELECT COUNT(*) AS commentTotal FROM comments c ";
//$commentTotalRes = query($commentTotalSql);
//$commentHeldSql = " SELECT COUNT(*) AS commentHeld FROM comments c WHERE status=0";
//$commentHeldRes = query($commentHeldSql);
$sql = " SELECT * FROM (SELECT COUNT(*) AS articleTotal FROM articles a) a JOIN (SELECT COUNT(*) AS articleDarfted FROM articles a WHERE a.status=0) b JOIN (SELECT COUNT(*) AS categoryTotal FROM categories c) c JOIN (SELECT COUNT(*) AS commentTotal FROM comments c) d JOIN 
(SELECT COUNT(*) AS commentHeld FROM comments c WHERE c.status=0) e ";
$res = query($sql);
$arr = array("code" => 101, "msg" => "操作失败");
if ($res) {
    $arr["code"] = 100;
    $arr["msg"] = "操作成功";
    $arr["articleTotal"] = $res[0]["articleTotal"];
    $arr["articleDarfted"] = $res[0]["articleDarfted"];
    $arr["categoryTotal"] = $res[0]["categoryTotal"];
    $arr["commentTotal"] = $res[0]["commentTotal"];
    $arr["commentHeld"] = $res[0]["commentHeld"];
}
echo json_encode($arr, JSON_UNESCAPED_UNICODE);
?>